package com.mh.example.xml.customtag;

import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class StudentBeanDefinitionDecorator implements BeanDefinitionDecorator {

	@Override
	public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
		Element element = (Element) node;
		Student student = toStudent(element);
		definition.getBeanDefinition().getPropertyValues().add("student", student);
		return definition;
	}

	private Student toStudent(Element element) {
		Student student = new Student();
		student.setName(element.getAttribute("name"));
		student.setEmail(element.getAttribute("email"));
		return student;
	}

}
